// mine.js

// 自定义标签
var app = getApp();
var iconPath = "../../images/icons/"
var tabs = [
    {
        "icon": iconPath + "mark.png",
        "iconActive": iconPath + "markHL.png",
        "title": "点击录入",
        "extraStyle": "",
    },
    
    
]
var userInfo = {
    avatar: "https://pic4.zhimg.com/e515adf3b_xl.jpg",
    nickname: "小闹钟",
    sex: "♂",  // 0, male; 1, female
    meta: '1篇日记',
}


Page({

    // data
    data: {
        radioId:"",
        loves:[
        {id:1, name:"男" },
        {id:2, name:"女" },
        ],
        pd:[
            {id:1,name:"是"},
            {id:2,name:"否"},
        ],
        jk:[
            {id:1,name:"良好"},
            {id:2,name:"待诊"},
            {id:3,name:"患病"},
        ],
        listData:[
            {"code":"01","text":"text1","type":"type1"},
            {"code":"02","text":"text2","type":"type2"},
            {"code":"03","text":"text3","type":"type3"},
            {"code":"04","text":"text4","type":"type4"},
            {"code":"05","text":"text5","type":"type5"},
            {"code":"06","text":"text6","type":"type6"},
            {"code":"07","text":"text7","type":"type7"}
          ]
          ,
        time:'',
        type:'',
        namei:'',
        sexi:'',
        sex:'',
        IDcardi:'',
        fileID:'',
        houseID:'',
        ioNumber:'',
        phone:'',
        TP:'',
        TPTF:'',
        BLYF:'',
        HXKN:'',
        JKZP:'',


        // 展示的tab标签
        tabs: tabs,

        // 当前选中的标签
        currentTab: "tab1",

        // 高亮的标签索引
        highLightIndex: "0",

        // 模态对话框样式 
        modalShowStyle: "",

        // 待新建的日记标题
        diaryTitle: "",

        // TODO 用户信息
        userInfo: userInfo,
    },
    //获取用户名
  getNamei(event) {
    console.log('获取输入的用户名', event.detail.value)
    this.setData({
     namei: event.detail.value
    })
    },
    //获取性别
  getSexi(event) {
    console.log('获取输入的性别', event.detail.value)
    this.setData({
     sexi: event.detail.value
    })
    },
    //获取身份证号
  getIDcardi(event) {
    console.log('获取输入的身份证号', event.detail.value)
    this.setData({
     IDcardi: event.detail.value
    })
    },
    //获取手机号码
  getPhone(event) {
    console.log('获取输入的手机号码', event.detail.value)
    this.setData({
     phone: event.detail.value
    })
    },
    //获取监测时间
    getTime(event) {
        console.log('获取输入的监测时间', event.detail.value)
        this.setData({
         time: event.detail.value
        })
        },
    //获取监测体温
  getTP(event) {
    console.log('获取输入的体温', event.detail.value)
    this.setData({
     TP: event.detail.value+"℃"
    })
    },
    //获取监测体温是否正常
  getTPTF(event) {
    console.log('获取输入的监测体温是否正常', event.detail.value)
    this.setData({
     TPTF: event.detail.value
    })
    },
     //获取是否有等状况
  getBLYF(event) {
    console.log('获取是否有等状况', event.detail.value)
    this.setData({
     BLYF: event.detail.value
    })
    },
     //获取是否呼吸困难
  getHXKN(event) {
    console.log('获取是否呼吸困难', event.detail.value)
    this.setData({
     HXKN: event.detail.value
    })
    },
     //获取健康总评
  getJKZP(event) {
    console.log('获取健康总评', event.detail.value)
    this.setData({
     JKZP: event.detail.value
    })
    },

    xzpx(){
        wx.navigateTo({
          url: '../px/px',
        })

    },
    //录入
    luru(){
        let namei = this.data.namei
        let sexi = this.data.sexi
        let IDcardi = this.data.IDcardi
        let phone = this.data.phone
        let time=this.data.time
        let TP = this.data.TP
        let TPTF = this.data.TPTF
        let BLYF = this.data.BLYF
        let HXKN = this.data.HXKN
        let JKZP = this.data.JKZP
        console.log(sexi)

        wx.cloud.database().collection('record').add({
            data: {
                namei:namei,
                sexi:sexi,
                IDcardi:IDcardi,
                phone:phone,
                time:time,
                TP:TP,
                TPTF:TPTF,
                BLYF:BLYF,
                HXKN:HXKN,
                JKZP:JKZP,
            },
            success(res) {
                console.log('录入成功', res)
                wx.showToast({
                 title: '录入成功',
                })
                wx.switchTab({
                 url: '../list/list',
                })
               },
               fail(res) {
                console.log('录入失败', res)
               }
              })

    },
    // 隐藏模态框
    hideModal() {
        this.setData({modalShowStyle: ""});
    },

    // 清除日记标题
    clearTitle() {
        this.setData({diaryTitle: ""});
    },

    onLoad:function(options){
            var mima=app.globalData.mima;
            console.log(abc);
            console.log(mima);
            this.setDate({
                mima:app.globalData.mima
            }
            )
          },
        onLaunch: function () {
            var that = this;
            that.globalData.mima = mima;
            this.setDate({
                mima:app.globalData.mima
            }
            )
          },
    onShow() {
        var mima=app.globalData.mima;
        this.setDate({
            mima:app.globalData.mima
        }
        )
        },

    // 点击tab项事件
    touchTab: function(event){
        var type=app.globalData.type;
        var mima=app.globalData.mima;
        console.log(mima);
        var name=app.globalData.name;
        var sex=app.globalData.sex;
        var IDcard=app.globalData.IDcard;
        var fileID=app.globalData.fileID;
        var houseID=app.globalData.houseID;
        var ioNumber=app.globalData.ioNumber;
        console.log(name);
        var tabIndex = parseInt(event.currentTarget.id);
        var template = "tab" + (tabIndex + 1).toString();

        this.setData({
            currentTab: template,
            highLightIndex: tabIndex.toString(),
            mima:app.globalData.mima,
            name:app.globalData.name,
            IDcard:app.globalData.IDcard,
            fileID:app.globalData.fileID,
            sex:app.globalData.sex,
            houseID:app.globalData.houseID,
            ioNumber:app.globalData.ioNumber,
            type:app.globalData.type
        }
        );
    },

    // 点击新建日记按钮
    touchAdd: function (event) {
        this.setData({
            modalShowStyle: "opacity:1;pointer-events:auto;"
        })
    },

    // 新建日记
    touchAddNew: function(event) {
        this.hideModal();

        wx.navigateTo({
            url: "../new/new?title=" + this.data.diaryTitle,
        });
    },

    // 取消标题输入
    touchCancel: function(event) {
        this.hideModal();
        this.clearTitle();
    }, 

    // 标题输入事件
    titleInput: function(event) {
        this.setData({
            diaryTitle: event.detail.value,
        })
    }
})
